package com.luo.ai.assistant.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luo.ai.assistant.conv.model.Chat;
import com.luo.ai.assistant.conv.model.ChatQuery;
import com.luo.ai.assistant.conv.model.ConvPageQuery;
import com.luo.ai.assistant.conv.model.Conversation;
import com.luo.ai.assistant.conv.service.ChatService;
import com.luo.ai.assistant.conv.service.ConversationService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会话管理
 *
 * @author luohq
 * @date 2025-02-02
 */
@RestController
@RequestMapping("/ai/convs")
public class ConversationController {
    private final ConversationService conversationService;
    private final ChatService chatService;


    public ConversationController(ConversationService conversationService, ChatService chatService) {
        this.conversationService = conversationService;
        this.chatService = chatService;
    }

    @PostMapping
    public Conversation addConversation() {
        return conversationService.addConversation();
    }

    @DeleteMapping("/{ids}")
    public void deleteConversations(@PathVariable("ids") List<Long> ids) {
        conversationService.deleteConversations(ids);
    }

    @GetMapping
    public Page<Conversation> getConversations(ConvPageQuery pageQuery) {
        return conversationService.getConversations(pageQuery);
    }



    @PostMapping("/{convId}/chats")
    public void addChat(@PathVariable Long convId, @RequestBody Chat chat) {
        chat.setConversationId(convId);
        chatService.addChat(chat);
    }

    @GetMapping("/{convId}/chats")
    public List<Chat> getChats(ChatQuery chatQuery) {
        return chatService.findChatHistory(chatQuery);
    }
}